@extends('admin.layout')
@section('title', '第三方用户')
@section('content')
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="id" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">邮箱</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <select name="sex">
                                <option value="0">不限</option>
                                <option value="1">男</option>
                                <option value="2">女</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-user-front-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-useradmin" data-type="batchdel">删除</button>
                    <button class="layui-btn layuiadmin-btn-useradmin" data-type="add">添加</button>
                </div>

                <table id="LAY-user-manage" lay-filter="LAY-user-manage">
                    <thead>
                    <tr class="text-c">
                        <th width="80">ID</th>
                        <th width="100">文章标题</th>
                        <th width="80">作者</th>
                        <th width="130">加入时间</th>
                        <th width="100">操作</th>
                    </tr>
                    </thead>

                </table>

            </div>
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript" src="/static/layuiadmin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/static/layuiadmin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
    <script>
        // 列表显示
        var dataTable = $('#LAY-user-manage').DataTable({
            // 下接的分页数量
            lengthMenu: [5, 10, 15, 20, 100],
            // 隐藏搜索
            searching: false,
            columnDefs: [
                // 索引第3列，不进行排序
                {targets: [3], orderable: false}
            ],
            // 开启服务器端分页 开启ajax
            serverSide: true,
            // 进行ajax请求
            ajax: {
                // 请求地址
                url: '{{ route('admin.oauth.index') }}',
                // 请求方式
                type: 'get',
                // 参数 动态获取表单数据用 function
                data: function (ret) {
                    ret.datemin = $('#datemin').val();
                    ret.datemax = $('#datemax').val();
                    ret.title = $.trim($('#title').val());
                }
            },
            // 指定每一列显示的数据
            columns: [
                //{'data': '字段名称1', "defaultContent": "默认值", 'className': '类名'},
                {data: 'id', className: 'text-c'},
                {data: 'user_id'},
                {data: 'nickname'},
                {data: 'created_at'},
                {data: 'aaa', defaultContent: '默认值'}
            ],
            // 回调方法
            // row 当前行的dom对象
            // 当前行的数据
            // 当前行的数据索引
            createdRow: function (row, data, dataIndex) {
                // 当前id
                var id = data.id;
                // 行的最后一列
                var td = $(row).find('td:last-child');
                // 显示的html内容
                var html = `
            <a href="/admin/article/${id}/edit" class="label label-secondary radius">修改</a>
            <a href="/admin/article/${id}" onclick="return delArticle(event,this)" class="label label-warning radius">删除</a>
          `;
                // html添加到td中
                td.html(html);
            }
        });

        layui.config({
            base: '/static/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'useradmin', 'table'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table;

            //监听搜索
            form.on('submit(LAY-user-front-search)', function(data){
                var field = data.field;

                //执行重载
                table.reload('LAY-user-manage', {
                    where: field
                });
            });

            //事件
            var active = {
                batchdel: function(){
                    var checkStatus = table.checkStatus('LAY-user-manage')
                        ,checkData = checkStatus.data; //得到选中的数据

                    if(checkData.length === 0){
                        return layer.msg('请选择数据');
                    }

                    layer.prompt({
                        formType: 1
                        ,title: '敏感操作，请验证口令'
                    }, function(value, index){
                        layer.close(index);

                        layer.confirm('确定删除吗？', function(index) {

                            //执行 Ajax 后重载
                            /*
                            admin.req({
                              url: 'xxx'
                              //,……
                            });
                            */
                            table.reload('LAY-user-manage');
                            layer.msg('已删除');
                        });
                    });
                }
                ,add: function(){
                    layer.open({
                        type: 2
                        ,title: '添加用户'
                        ,content: "{{ route('admin.user.create') }}"
                        ,maxmin: true
                        ,area: ['500px', '450px']
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var iframeWindow = window['layui-layer-iframe'+ index]
                                ,submitID = 'LAY-user-front-submit'
                                ,submit = layero.find('iframe').contents().find('#'+ submitID);

                            //监听提交
                            iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                                var field = data.field; //获取提交的字段

                                //提交 Ajax 成功后，静态更新表格中的数据
                                //$.ajax({});
                                table.reload('LAY-user-front-submit'); //数据刷新
                                layer.close(index); //关闭弹层
                            });

                            submit.trigger('click');
                        }
                    });
                }
            };

            $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
        });
    </script>
@endsection

